﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Navigation;
using Microsoft.Phone.Controls;
using Microsoft.Phone.Shell;
using System.Windows.Resources;

namespace Chromatics.Pages
{
    public partial class SettingsPage : PhoneApplicationPage
    {
        public SettingsPage()
        {
            InitializeComponent();
            this.setSound();
            this.setMusic();
        }

        private void setSound()
        {
            if (DataLoader.Instance.LoadUserSettings().Sound == true)
            {
                this.SoundChange.Content = "Sound ON";
            }
            else
            {
                this.SoundChange.Content = "Sound OFF";
            }
        }

        private void setMusic()
        {
            if (DataLoader.Instance.LoadUserSettings().Music == true)
            {
                this.MusicChange.Content = "Music ON";
            }
            else
            {
                this.MusicChange.Content = "Music OFF";
            }
        }

        private void ResetBtn_Tap(object sender, System.Windows.Input.GestureEventArgs e)
        {
            SoundPlayer.PlayDing();
            DataLoader.Instance.ResetAllLevels();
        }

        private void SoundChange_Tap(object sender, System.Windows.Input.GestureEventArgs e)
        {
            SoundPlayer.PlayDing();
            DataLoader.Instance.SaveUserSettings(new UserSettings() { Sound = !DataLoader.Instance.LoadUserSettings().Sound, Music = DataLoader.Instance.LoadUserSettings().Music });
            this.setSound();
        }

        private void PhoneApplicationPage_BackKeyPress_1(object sender, System.ComponentModel.CancelEventArgs e)
        {
            SoundPlayer.PlayDing();
        }

        private void MusicChange_Tap(object sender, System.Windows.Input.GestureEventArgs e)
        {
            SoundPlayer.PlayDing();
            DataLoader.Instance.SaveUserSettings(new UserSettings() { Sound = DataLoader.Instance.LoadUserSettings().Sound, Music = !DataLoader.Instance.LoadUserSettings().Music });
            this.setMusic();
            if (DataLoader.Instance.LoadUserSettings().Music == true)
            {
                App.PlayBackMusic();
            }
            else
            {
                App.StopBackMusic();
            }
        }
    }
}